package com.ruoyi.hr.controller.hr.welfare.welfarecalculationconfig;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hr.domain.welfare.welfarecalculationconfig.CcdBenefitbase;
import com.ruoyi.hr.service.welfare.welfarecalculationconfig.ICcdBenefitbaseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 福利基数Controller
 * 
 * @author zeo
 * @date 2019-12-26
 */
@Controller
@RequestMapping("/welfare/benefitbase")
public class CcdBenefitbaseController extends BaseController
{
    private String prefix = "hr/welfare/welfarecalculationconfig/welfarebase";

    @Autowired
    private ICcdBenefitbaseService ccdBenefitbaseService;

    @RequiresPermissions("system:benefitbase:view")
    @GetMapping()
    public String benefitbase()
    {
        return prefix + "/benefitbase";
    }

    /**
     * 查询福利基数列表
     */
    @RequiresPermissions("system:benefitbase:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CcdBenefitbase ccdBenefitbase)
    {
        List<CcdBenefitbase> list = ccdBenefitbaseService.selectCcdBenefitbaseList(ccdBenefitbase);
        return getDataTable1(list, list.size());
    }

    /**
     * 导出福利基数列表
     */
    @RequiresPermissions("system:benefitbase:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CcdBenefitbase ccdBenefitbase)
    {
        List<CcdBenefitbase> list = ccdBenefitbaseService.selectCcdBenefitbaseList(ccdBenefitbase);
        ExcelUtil<CcdBenefitbase> util = new ExcelUtil<CcdBenefitbase>(CcdBenefitbase.class);
        return util.exportExcel(list, "benefitbase");
    }

    /**
     * 新增福利基数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存福利基数
     */
    @RequiresPermissions("system:benefitbase:add")
    @Log(title = "福利基数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CcdBenefitbase ccdBenefitbase)
    {
        int num = ccdBenefitbaseService.insertCcdBenefitbase(ccdBenefitbase);
        return toAjax(num);
    }

    /**
     * 修改福利基数
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CcdBenefitbase ccdBenefitbase = ccdBenefitbaseService.selectCcdBenefitbaseById(id);
        mmap.put("ccdBenefitbase", ccdBenefitbase);
        return prefix + "/edit";
    }

    /**
     * 修改保存福利基数
     */
    @RequiresPermissions("system:benefitbase:edit")
    @Log(title = "福利基数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CcdBenefitbase ccdBenefitbase)
    {
        return toAjax(ccdBenefitbaseService.updateCcdBenefitbase(ccdBenefitbase));
    }

    /**
     * 删除福利基数
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ccdBenefitbaseService.deleteCcdBenefitbaseByIds(ids));
    }
}
